package com.zmn.plat.dubbo.impl.msg;

import javax.annotation.Resource;

import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
import org.apache.dubbo.config.annotation.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.plat.business.interfaces.msg.MsgBService;
import com.zmn.plat.common.exception.PlatException;
import com.zmn.plat.dubbo.dto.msg.MsgDIO;
import com.zmn.plat.dubbo.interfaces.msg.MsgRemoteService;
import com.zmn.plat.dubbo.utils.DubboConsts;

/**
 * 通过消息管理系统配置的模板发送消息
 * 
 * @author linfeng
 * @since 2020/06/01 19:27
 */
@Service(loadbalance = "roundrobin", timeout = 5000, retries = -1, version = DubboConsts.INTERFACE_VERSION, validation = "true")
public class MsgRemoteServiceImpl implements MsgRemoteService {

    private Logger logger = LoggerFactory.getLogger(MsgRemoteServiceImpl.class);

    @Resource
    MsgBService msgBService;

    /**
     * 根据消息模板配置发送消息：可发钉钉，短信，站内信
     * 
     * @param msgDIO
     * @return
     */
    @Override
    @ReadOnlyConnection
    public ResponseDTO<Boolean> sendMsg(MsgDIO msgDIO) {
        try {
            Boolean result = msgBService.sendMsg(msgDIO);
            return ResponseDTO.success(result);
        } catch (PlatException e) {
            logger.error("sendMsg error...", e);
            return ResponseDTO.success(false, e.getMessage());
        } catch (Exception e) {
            logger.info("发送消息失败：{}", e);
            return ResponseDTO.success(false, "发送消息失败！");
        }
    }
}
